﻿using Shop.Logic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Shop
{
    public partial class Form1 : Form
    {
        Controller controller;
        public Form1()
        {
            Shop.Program.DataIO.ToForm1 = new Shop.Program.DataIO.MyEvent(events);
            InitializeComponent();
            controller = new Controller();
        }

        void events(List<Object> obj)
        {
            if (obj.Count == 1)
            {
                String text = (String)obj[0];
                if (text == "Close")
                {
                    this.Close();
                }
                if (text == "Out")
                {
                    this.Show();
                }
            }
        }

        private void maskedTextBox1_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.KeyValue == 13)
            {
                Check();
            }
                
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Check();
        }

        void Check()
        {
            if ((surname.Text.Trim() != "") && (password.Text.Trim() != ""))
                if (controller.Autorization(surname.Text.Trim(), password.Text.Trim()))
                    this.Hide();
        }
    }
}
